﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Exhibition.RenderTemplete.Controls;
using Exhibition.Common.Helper;
using Exhibition.Dao.ViewModel;
using Exhibition.Service;

namespace Exhibition.Manage
{
    public partial class BoothClassDetail : BaseAdminPage
    {
        BoothClassModel model = new BoothClassModel();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack) {
                hfId.Value = reqID.ToString();
                LoadData();
            }
        }

        private void LoadData()
        {
            //List<BoothClassModel> models = CenterService.boothClassService.GetBoothClassList(0,1);
            //drpClass.DataTextField = "ClassType";
            //drpClass.DataValueField = "Id";
            //drpClass.DataSource = models;
            //drpClass.DataBind();
            //drpClass.Items.Insert(0,new ListItem("请选择","0"));
            model = CenterService.boothClassService.GetOneById(reqID);
            if (model != null)
            {
                txtName.Value = model.ClassType;

                //if (mdl != null) {
                //    drpClass.SelectedValue = mdl.PreId.ToString();

                //}
                txtUnit.Text = model.Uint.ToString();
                txtPrice.Text = model.Price.ToString();
            }
            
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            model = string.IsNullOrEmpty(hfId.Value)||hfId.Value=="0" ? new BoothClassModel() : CenterService.boothClassService.GetOneById(Convert.ToInt32(hfId.Value));
            //分类名称
            model.ClassType = txtName.Value;

            //单位(平方米)
            model.Uint = Convert.ToInt32(txtUnit.Text);

            //价格
            model.Price = Convert.ToDecimal(txtPrice.Text);
            model.SiteID = CurrentSite.Id;
            if (hfId.Value != "0")
            {
                model.CreateUserId = AdminUser.Id;
            }////楼层ID
            //model.FloorID = Convert.ToInt32(txtFloorID.Value);

            if (CenterService.boothClassService.Save(model) > 0)
            {

                JsHelper.Unblock(this, CommFunMsg.GetMessage("A0001", Lan.zh));
            }
            else
            {
                JsHelper.Alert(this, CommFunMsg.GetMessage("E0001", Lan.zh));
            }

        }
    }
}